package com.example.flshtarvel.controller;

import com.example.flshtarvel.entity.ArticleType;
import com.example.flshtarvel.service.ArticleTypeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class ArticleTypeController {
    @Autowired
    ArticleTypeService articleTypeService;

    @PostMapping("/articleType")
    public Map<String,Object> insertArticleType(ArticleType articleType){
        Map<String,Object> map = new HashMap<String,Object>();
        int tag = articleTypeService.insertMessageType(articleType);
        if(tag==1){
            map.put("msg",0);
            map.put("messageType",articleType);
        }else{
            map.put("msg",0);
        }
        return map;
    }

    @GetMapping("/articleType")
    public Map<String,Object> selectAllArticleType(){
        Map<String,Object> map = new HashMap<String,Object>();
        List<ArticleType> articleTypeList = articleTypeService.selectAllArticleType();
        if(articleTypeList.isEmpty()){
            map.put("msg",0);
        }else{
            map.put("msg",1);
            map.put("articleTypeList",articleTypeList);
        }
        return map;
    }
}
